#pragma once
#include <iostream>
#include <string>
#include "SDLComponent.h"
#include "SDLResources.h"
#include "SDL_image.h"
class SDLSprite : public SDLComponent
{
public:
	SDLSprite();
	SDLSprite(std::string fileName);
	SDLSprite(std::string fileName, int dstX, int dstY);
	SDLSprite(std::string fileName, int srcX, int srcY, int srcW, int srcH, int dstX, int dstY);
	SDLSprite(std::string fileName, SDL_Rect& src, int dstX, int dstY);
	SDLSprite(std::string fileName, int srcX, int srcY, int srcW, int srcH, SDL_Rect& dst);
	SDLSprite(std::string fileName, SDL_Rect& src, SDL_Rect& dst);
	virtual ~SDLSprite();

	int GetX(){ return dstRect.x; }
	int GetY(){ return dstRect.y; }
	int GetDestW(){ return dstRect.w; }
	int GetDestH(){ return dstRect.h; }
	int GetSourceW(){ return srcRect.w; }
	int GetSourceH(){ return srcRect.h; }
		
	void SetDepth(int depth);
	void SetPosition(int x, int y){ dstRect.x = x; dstRect.y = y; }
	void SetSrcRect(int x, int y, int w, int h)
	{ 
		srcRect.x = x;
		srcRect.y = y;
		srcRect.w = w;
		srcRect.h = h;
		dstRect.w = w;
		dstRect.h = h;
	}	
	void SetDstRect(int x, int y, int w, int h)
	{
		dstRect.x = x;
		dstRect.y = y;
		dstRect.w = w;
		dstRect.h = h;
	}

	void SetOffPoint(int x, int y)
	{
		offPoint.x = x;
		offPoint.y = y;
	}

	void Scale(int increment)
	{
		offPoint.x = dstRect.w / 2;
		offPoint.y = dstRect.h / 2;

		dstRect.w += increment;
		dstRect.h += increment;
	}

	void ScaleBy(float multiplicator);


	void SetTexture(std::string fileName)
	{
		SetTexture(SDLResources::GetInstance()->GetTexture(fileName)); 
	}

	void SetTexture(SDL_Texture* latexture)
	{ 
		texture = latexture; 
		SetTexRect(texture);
	}

	void SetTexRect(SDL_Texture* tex)
	{
		if(srcRect.w == 0 || srcRect.h == 0)
		{
			SDL_QueryTexture(texture, 0, 0, &dstRect.w, &dstRect.h);
			srcRect.w = dstRect.w;
			srcRect.h = dstRect.h;
		}
		else
		{
			dstRect.w = srcRect.w;
			dstRect.h = srcRect.h;
		}
	}
	void SetVisible(bool visible){ this->visible = visible; }

	void calculeCenterPoint()
	{ 
		centerPoint.x = (int)((float)dstRect.x + (float)dstRect.w / 2.0f);
		centerPoint.y = (int)((float)dstRect.y + (float)dstRect.h / 2.0f);
	}

	SDL_Texture* GetTexture(){return texture;}

	virtual void Start();
	virtual void Stop();
	virtual void Update();
	virtual void Draw();

protected:

	bool visible;
	SDL_Rect srcRect;
	SDL_Rect dstRect;
	SDL_Point offPoint;
	SDL_Point centerPoint;
	SDL_Texture* texture;

	void ApplySurface(SDL_Texture* texture, SDL_Renderer* renderer);
};

